package com.example.controller.pc;

import com.example.common.result.Result;
import com.example.entity.dto.pc.PcMoctaListDto;
import com.example.entity.dto.pc.SortDto;
import com.example.entity.vo.pc.PcMoctaList;
import com.example.mapper.MoctaMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "排产工单展示")
@RequestMapping("/api/pcMocta")
public class PcMoctaController {

    @Autowired
    private MoctaMapper moctaMapper;

    @ApiOperation("排产工单列表")
    @PostMapping("getPcMoctaList")
    public Result<PageInfo<PcMoctaList>> getPcMoctaList(@RequestBody PcMoctaListDto dto) {
        System.out.println(dto.getSortList());
        List<SortDto> list = dto.getSortList();
        StringBuffer sb = new StringBuffer();
        for(SortDto sortDto : list) {
            sb.append(sortDto.getName()).append(" ").append(sortDto.getSxjx().equals("1") ? "ASC" : "DESC").append(",");
        }
        if (sb.length() > 0) sb.deleteCharAt(sb.length() - 1);
        if(sb.length() == 0) PageHelper.startPage(dto.getPageNum(), dto.getPageSize(), "MA028 ASC,E.GXSL DESC,A.TA015 DESC,A.TA010,A.TA009");
        else PageHelper.startPage(dto.getPageNum(), dto.getPageSize(), sb.toString());
        List<PcMoctaList> pcMoctaList = moctaMapper.getPcMoctaList("");
        PageInfo<PcMoctaList> res = new PageInfo<>(pcMoctaList);
        return Result.success(res);
    }

}
